package com.tanhua.model.vo;

import com.tanhua.model.domain.QuestionOption;
import com.tanhua.model.domain.SoulQuestion;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

/**
 * @author げっしょく
 * @date 2021/11/9
 */

@Data
@NoArgsConstructor
@AllArgsConstructor
public class SoulQuestionVo implements Serializable {
    private String id;
    private String question;
    private List<OptionsVo> options;

    public static SoulQuestionVo init(SoulQuestion soulQuestion, List<OptionsVo> options) {
        SoulQuestionVo vo = new SoulQuestionVo();
        vo.setId(soulQuestion.getId().toString());
        vo.setQuestion(soulQuestion.getQuestion());
        vo.setOptions(options);
        return vo;
    }
}


/*
   @Override
    public List<SoulListVo> getSoulListVo(Long userId) {
        //查询所有的测试列表
        List<SoulList> soulLists = soulListMapper.selectList(null);
        if (CollUtil.isEmpty(soulLists)) {
            return new ArrayList<>();
        }
        List<Long> soulListIDs = soulLists.stream().map(s -> s.getId()).collect(Collectors.toList());
        //通过列表id查询出对应的问题
        Map<Long, List<SoulQuestion>> questionMap = new HashMap<>();
        List<Long> questionIds = new ArrayList<>();
        QueryWrapper qw = null;
        for (Long soulListID : soulListIDs) {
            qw = new QueryWrapper();
            qw.eq("soulId", soulListID);
            List<SoulQuestion> list = soulQuestionMapper.selectList(qw);
            questionMap.put(soulListID, list);
            for (SoulQuestion soulQuestion : list) {
                questionIds.add(soulQuestion.getId());
            }
        }
        //通过问题id查询出所有的答案
        for (Long questionId : questionIds) {
            qw = new QueryWrapper();
            qw.eq("question_id", questionId);
            List<QuestionOption> list = questionOptionMapper.selectList(qw);

        }
        List<QuestionOption> list1 = questionOptionMapper.selectList(qw);
        if (CollUtil.isEmpty(list1)) {
            return new ArrayList<>();
        }
/*        Map<Long, QuestionOption> collect = list1.stream()
                .collect(Collectors.toMap(q -> q.getQuestionId(), Function.identity()));*/
//通过userId查询出当前用户最近的一条测试答案
/*
        qw = new QueryWrapper();
                qw.eq("userId", userId);
                qw.orderByDesc("created");
                List<TestResult> testResults = testResultMapper.selectList(qw);
        if (CollUtil.isEmpty(testResults)) {
        return new ArrayList<>();
        }
        //获取最近一条测试的id
        Long id = testResults.get(0).getId();
        //封装数据
        List<SoulListVo> vos = new ArrayList<>();


        return vos;
        }
 */